//
//  LYstatusRetweetedView.swift
//  微博
//
//  Created by liuerying on 16/5/25.
//  Copyright © 2016年 liuerying. All rights reserved.

//转发微博的视图

import UIKit
import SnapKit

class LYstatusRetweetedView: UIView {

    //绑定一个视图模型
    var bottomCons:Constraint?
    
    var statusViewModel: LYStatusViewModel? {
    
        didSet{
        
            contentLabel.text = statusViewModel?.status?.retweeted_status?.text
            
            pictureView.pictures = statusViewModel?.status?.retweeted_status?.pic_urls
       
            //解绑
            bottomCons?.uninstall()
            //在转发微博中需要判断转发微博的配图视图数组
            if let url = statusViewModel?.status?.retweeted_status?.pic_urls where url.count > 0{
            
                pictureView.pictures = url
                
                self.snp_makeConstraints(closure: { (make) in
                  self.bottomCons = make.bottom.equalTo( pictureView.snp_bottom).offset(StatusCellMargin).constraint
                })
                
                pictureView.hidden = false
                
            }else{
            
                //没有配图微博
                pictureView.pictures = nil
                
                self.snp_makeConstraints(closure: { (make) in
                  self.bottomCons = make.bottom.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin).constraint
                })
                
                pictureView.hidden = true
            }
        }
  
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        //设置转发的背景颜色
        backgroundColor = UIColor(white: 0.95, alpha: 1)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置ui界面
   private func setupUI(){
    
    addSubview(contentLabel)
    addSubview(pictureView)
    
    contentLabel.snp_makeConstraints { (make) in
        make.top.left.equalTo(self).offset(StatusCellMargin)
        
    }
    
    //设置图片的约束
    pictureView.snp_makeConstraints { (make) in
        //设置顶部约束
        make.top.equalTo(contentLabel.snp_bottom).offset(StatusCellMargin)
    
        make.left.equalTo(self).offset(StatusCellMargin)
    }
    
    
    self.snp_makeConstraints { (make) in
       self.bottomCons = make.bottom.equalTo(pictureView.snp_bottom).offset(StatusCellMargin).constraint
    }
    
    
   
        
    }
    
    lazy var contentLabel:UILabel = UILabel(title: "嘻哈", font: 14, textcolor: UIColor.darkGrayColor(), alignment:.Left)
    
    //图片视图
    lazy var pictureView :LYStatusPictureView = LYStatusPictureView()
}
